<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<style>
:lang(no), :lang(no) + div > span,
:lang(en), :lang(en) + div > span { background-color: green }
</style>
<div id="norwegian"></div>
<div>
    <div></div>
    <div></div>
    <div></div>
    <span id="nospan"></span>
</div>
<div id="english"></div>
<div>
    <div></div>
    <div></div>
    <div></div>
    <span id="enspan"></span>
</div>
<script>
description("Use descendant invalidation set for :lang pseudo class.")

var transparent = "rgba(0, 0, 0, 0)";
var green = "rgb(0, 128, 0)";

shouldBe("getComputedStyle(norwegian).backgroundColor", "transparent");
shouldBe("getComputedStyle(nospan).backgroundColor", "transparent");
shouldBe("getComputedStyle(english).backgroundColor", "transparent");
shouldBe("getComputedStyle(enspan).backgroundColor", "transparent");

document.documentElement.offsetTop; // Force recalc.
norwegian.lang = "no";

if (window.internals)
    shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "2");

shouldBe("getComputedStyle(norwegian).backgroundColor", "green");
shouldBe("getComputedStyle(nospan).backgroundColor", "green");

document.documentElement.offsetTop; // Force recalc.
english.setAttributeNS("http://www.w3.org/XML/1998/namespace", "lang", "en");

if (window.internals)
    shouldBe("internals.updateStyleAndReturnAffectedElementCount()", "2");

shouldBe("getComputedStyle(english).backgroundColor", "green");
shouldBe("getComputedStyle(enspan).backgroundColor", "green");
</script>
